package flex.cc.uac.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import flex.cc.AccessKeyAndSecretUtil;
import flex.cc.PublicUtil;
import flex.cc.base.dto.LoginAuthDto;
import flex.cc.core.utils.RequestUtil;
import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.stereotype.Service;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import flex.cc.uac.dao.UacCalllerDao;
import flex.cc.uac.entity.UacCalllerEntity;
import flex.cc.uac.service.UacCalllerService;
import org.springframework.transaction.annotation.Transactional;


@Service("uacCalllerService")
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class UacCalllerServiceImpl extends ServiceImpl<UacCalllerDao, UacCalllerEntity> implements UacCalllerService {


    @Override
    public String addCalllerInfo(Map map) {
        UacCalllerEntity entity = new UacCalllerEntity();
        String returnData = null;
        LoginAuthDto loginuser = RequestUtil.getLoginUser();
        if(PublicUtil.isEmpty(map.get("id"))){
            returnData="新增成功";
            String accessKey = AccessKeyAndSecretUtil.getAccessKey();
            String accessSecret = AccessKeyAndSecretUtil.getAccessSecret(accessKey);
            entity.setAccessKey(accessKey);
            entity.setAccessSecret(accessSecret);
        }else{
            returnData="编辑成功";
            entity.setId(Long.parseLong(map.get("id").toString()));
        }
        entity.setCallerCode(map.get("callerCodes").toString());
        entity.setCallerName(map.get("callerNames").toString());
        entity.setCallerNum(map.get("callerNums").toString());
        entity.setRemark(PublicUtil.isEmpty(map.get("remarks"))?"":map.get("remarks").toString());
        entity.setUpdateInfo(loginuser);
        this.saveOrUpdate(entity);
        return returnData;
    }

    @Override
    public void deleteCallerInfoById(Long id) {
        this.removeById(id);
    }

    @Override
    public UacCalllerEntity queryCallerInfoById(Long id) {
        return this.getOne(new QueryWrapper<UacCalllerEntity>().eq("id",id));
    }
}